import React, { Component, PropTypes } from 'react';

import '../BodyDataInput.scss';
import LayoutView, { LayoutMode } from '../../layout';
import { SelectItemList, SelectItem } from '../../common-ui-parts';
import { BodyItemConstant as BiC } from '../../../constants/InputItemConstants';
import { BodyDataInputContextConstant } from '../../../constants/ComponentContextConstants';

// 質問に関するイラスト
import imgQ7 from './images/imgQ7.png';

/**
 * Q7.塩蔵品
 */
class Question07 extends Component {
  getChildContext() {
    const { [BiC.SALINE_FOOD]: salineFood } = this.context.parent.inputData;
    return Object.freeze({
      parent: Object.freeze(Object.assign({}, this.context.parent, {
        // 未入力の場合、[次へ]ボタンは無効
        disabledNext: salineFood === undefined,
      })),
    });
  }

  shouldComponentUpdate(nextProps, nextState) {
    return this.context.parent.pageIndex === nextProps.index;
  }

  scrollPageTop() {
    this.refs.layoutView.getWrappedInstance().scrollTop();
  }

  validatePage() {
    // 入力チェック（true:チェックOK）
    return this.context.parent.validateQuestionPage([BiC.SALINE_FOOD]);
  }

  render() {
    const { inputData, errorInfo, updateState } = this.context.parent;
    return (
      <LayoutView
        ref="layoutView"
        mode={LayoutMode.QUESTION}
        title="塩蔵品"
        question={{
          no: 7,
          sentence: <p>塩辛・たらこなどの塩蔵品は<br/>週にどのくらい食べますか？<br/><br/></p>,
          illustSrc: imgQ7,
          illustHeight: 194,
          helpTitle: 'Q7. 塩蔵品について',
          helpText: <p>過去1年間の食事を思い出して、平均的な頻度を答えてください。</p>,
        }}
        errorText={errorInfo.get(BiC.SALINE_FOOD)}
      >
        {/* 塩蔵品 */}
        <dl className="content">
          <dt style={{ display: 'none' }}>{BiC.SALINE_FOOD.label}</dt>
          <dd>
            <SelectItemList
              name={BiC.SALINE_FOOD}
              value={inputData[BiC.SALINE_FOOD]}
              placeholder="選択してください"
              propagate={updateState}
            >
              {BiC.SALINE_FOOD.choices.map((choice, index) => (
                <SelectItem key={index} value={choice.value} label={choice.label} />
              ))}
            </SelectItemList>
          </dd>
        </dl>
      </LayoutView>
    );
  }

}

Question07.contextTypes = BodyDataInputContextConstant;
Question07.childContextTypes = Question07.contextTypes;

/*Question07.propTypes = {
  index: PropTypes.number,    // 自ページINDEX（0～）
};*/

export default Question07
